<template>
  <div class="GoldRecord">
    <div class="card">
      <img class="wenhao" src="../assets/image/wenhao.png" alt="" />
      <h2>
        <div>
          <span>
            <img src="../assets/image/jinbi.png" alt="" />
          </span>
          4256
        </div>
      </h2>
    </div>
    <div class="choose">
      <div
        class="recharge"
        :class="{ active: active == 1 ? true : false }"
        @click="chooseType(1)"
      >
        <div>充值记录</div>
        <span class="line"></span>
      </div>
      <div
        @click="chooseType(2)"
        class="consumption"
        :class="{ active: active == 2 ? true : false }"
      >
        <div>消费记录</div>
        <span class="line"></span>
      </div>
    </div>
    <!-- 列表 -->
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <img
        class="empty"
        v-if="list.length == 0"
        src="../assets/image/kong.png"
        alt=""
      />
      <div v-else class="item" v-for="(item, index) in list" :key="index">
        <div class="left">
          <div class="txt">充值100</div>
          <div class="time">2021.01.15 00:45</div>
        </div>
        <div class="right">
          <img src="../assets/image/jinbi.png" alt="" />
          <span>+88</span>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script>
export default {
  data() {
    return {
      active: 1,
      loading: false,
      finished: false,
      list: [],
      total: "",
      page: 1,
    };
  },
  methods: {
    chooseType(value) {
      this.active = value;
      this.list = [];
      this.finished = false;
      this.total = "";
      this.page = 1;
      this.onLoad();
    },
    onLoad() {
      if (this.active == 1) {
        console.log(1);
        setTimeout(() => {
          for (let i = 0; i < 10; i++) {
            this.list.push(this.list.length + 1);
          }

          // 加载状态结束
          this.loading = false;

          // 数据全部加载完成
          if (this.list.length >= 40) {
            this.finished = true;
          }
        }, 1000);
      } else {
        console.log(2);
        this.list = [];
        this.loading = false;
        this.finished = true;
      }
    },
  },
};
</script>

<style lang="less" scoped>
.GoldRecord {
  padding: 15px;
  // height: 100%;
  min-height: 100%;
  background-color: #f5f5f5;
  .card {
    height: 88px;
    background: url(../assets/image/rechargeCard.png) no-repeat;
    background-size: 100% 100%;
    position: relative;
    padding-top: 26px;
    box-sizing: border-box;
    .wenhao {
      position: absolute;
      top: 5px;
      right: 5px;
      width: 16px;
      height: 16px;
    }
    h2 {
      text-align: center;
      display: flex;
      align-items: center;
      justify-content: space-around;
      div {
        display: flex;
        align-items: center;
        font-size: 24px;
        font-family: Alibaba PuHuiTi;
        font-weight: bold;
        line-height: 33px;
        color: #ffffff;
        img {
          width: 30px;
          height: 30px;
          margin-right: 8px;
        }
      }
    }
  }
  .choose {
    margin-top: 16px;
    font-size: 15px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #666666;
    display: flex;
    height: 18px;
    .recharge {
      margin-right: 24px;
    }
    .active {
      div {
        font-weight: bold;
        color: #333333;
      }
      .line {
        width: 10px;
        height: 2px;
        display: block;
        background: #9981ed;
        border-radius: 3px;
        margin: 0 auto;
      }
    }
  }
  .van-list {
    margin-top: 14px;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    padding: 10px;
    .empty {
      padding: 30px;
      box-sizing: border-box;
    }
    .item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding-bottom: 10px;
      border-bottom: 1px solid #f5f5f5;
      margin-bottom: 10px;
      .left {
        .txt {
          font-size: 15px;
          font-family: PingFang SC;
          font-weight: 500;
          color: #333333;
        }
        .time {
          font-size: 12px;
          font-family: PingFang SC;
          font-weight: 400;
          line-height: 17px;
          color: #666666;
        }
      }
      .right {
        display: flex;
        align-items: center;
        img {
          width: 20px;
          height: 20px;
          margin-right: 5px;
        }
        span {
          font-size: 15px;
          font-family: PingFang SC;
          font-weight: 500;
          line-height: 21px;
          color: #462e99;
        }
      }
    }
  }
}
</style>